package com.shop.shopcommon.token;

import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 手机验证码登录令牌
 */
public class PhoneVerificationToken extends AbstractAuthenticationToken {
    private final Object phone;
    private Object verificationCode;

    public PhoneVerificationToken(Object phone, Object verificationCode) {
        super(null);
        this.phone = phone;
        this.verificationCode = verificationCode;
        setAuthenticated(false);
    }

    /**
     * 认证成功令牌构造器
     */
    public PhoneVerificationToken(Object phone, Object verificationCode, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        System.out.println(phone);
        this.phone = phone;
        this.verificationCode = verificationCode;
        setAuthenticated(true);
    }



    @Override
    public Object getCredentials() {
        return verificationCode;
    }

    @Override
    public Object getPrincipal() {
        return phone;
    }

    @Override
    public void setDetails(Object details) {
        super.setDetails(details);
    }

    @Override
    public Object getDetails() {
        return super.getDetails();
    }

    // 清除凭证信息
    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        this.verificationCode = null;
    }
}

